package com.itheima.service.Impl;

import com.itheima.dao.AccountDao;
import com.itheima.service.AccountService;
import com.itheima.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private LogService logService;

    @Override
    public void transfer(String in, String out, Double money) {
        /**
         * 日志和转账属于同一个事务，因为默认就是小事务自动加入大事务，这里面就是log的事务自动加入到了转账事务
         */

        //想让某一段代码一定运行，用try-finally

        try {   //可能出错的代码
            accountDao.inMoney(in,money);

            accountDao.outMoney(out,money);

        } finally { //一定会执行的代码
            logService.log(in,out,money);
        }

    }
}
